home *** CD-ROM | disk | FTP | other *** search
- Path: svnews.ubinet.ubs.com!ubszh!ubszh!jis
- From: ian.johnston@ubs.com (Johnston Ian (by ubsswop))
- Newsgroups: comp.lang.c++
- Subject: Re: Newbie question on syntax of pointer to const
- Date: 31 Jan 1996 08:25:13 GMT
- Organization: UBS
- Distribution: world
- Message-ID: <4en919$o1h@ubszh.fh.zh.ubs.com>
- References: <4ej9eg$lq6@agate.berkeley.edu> <4ek468$jr1@clarknet.clark.net> <4ell6p$3f2q@yuma.ACNS.ColoState.EDU>
- NNTP-Posting-Host: nol2179.fh.zh.ubs.com
-
- In article <4ell6p$3f2q@yuma.ACNS.ColoState.EDU>, steffend@lamar.colostate.edu (Dave Steffen) writes:
- |> Harlan Messinger (gusty@clark.net) wrote:
- |> > parsons@vouvray.CS.Berkeley.EDU (David C. Parsons) wrote:
- |> > >(1) const double *pc; and
- |> > >(2) double const *pc;
- |>
- |> > This is one of my favorite questions to ask C/C++ programmers at job
- |> > interviews.
- |>
- |> > They are different. The first is a pointer to a constant double.
- |> (snip)
- |> > The second is a constant pointer to a double.
- |> (snip)
-
- Wrong. They are the same: a pointer to a const double.
-
- We went through all this about two months back. I hope Harlan Messinger
- never interviews me for a C++ job :-) :-) (Pity this didn't appear during
- that thread about c++ interviews ...)
-
- |>
- |> What I'm curious about is the syntax of that second
- |> line. Looking at Meyers' book, it looks like the const should come
- |> after the *. In other words, are these the same:
- |>
- |> double const * pc;
- |> double * const pc;
-
- The second one is absolutely correct if you want a constant pointer to
- a (mutable) double.
-
- Ian
-